﻿using System;
using System.IO;
using System.Reflection;
using System.Windows.Forms;
using CuteSprite.Eme.Data.Settlement;
using CuteSprite.Eme.UI.Utils;
using HmFramework.Components;
using HmFramework.Components.Controls;
using HmFramework.Components.Editors;
using HmFramework.Data;
using HmFramework.UI.Utils.Controls;

namespace CuteSprite.Eme.UI.Settlement
{
	public partial class FrmBsdSettlementSolution : EmeEntityForm
	{
		#region -- 构造 --

		#region - 新增 -

		/// <summary>默认构造函数</summary>
		public FrmBsdSettlementSolution()
			: base()
		{
			InitializeComponent();
			InitForm();
		}

		/// <summary>构造函数</summary>
		/// <param name="templateFileName">模板文件</param>
		public FrmBsdSettlementSolution(String templateFileName)
		{
			SetupFromXml(templateFileName);
			InitForm();
		}

		/// <summary>构造函数</summary>
		/// <param name="resourceName">模板资源文件</param>
		/// <param name="asm">模板资源文件所在程序集</param>
		public FrmBsdSettlementSolution(String resourceName, Assembly asm)
		{
			SetupFromXmlResource(resourceName, asm);
			InitForm();
		}

		/// <summary>构造函数</summary>
		/// <param name="stream">模板数据流</param>
		public FrmBsdSettlementSolution(Stream stream)
		{
			SetupFromXmlStream(stream);
			InitForm();
		}

		#endregion

		#region - 编辑或新增 -

		/// <summary>构造函数</summary>
		/// <param name="entity">实体对象</param>
		public FrmBsdSettlementSolution(IEntity entity)
			: this(entity, false)
		{
		}

		/// <summary>构造函数</summary>
		/// <param name="entity">实体对象</param>
		/// <param name="readOnly">是否只读，指定编辑还是浏览实体信息</param>
		public FrmBsdSettlementSolution(IEntity entity, Boolean readOnly)
			: base(entity, readOnly)
		{
			InitializeComponent();
			InitForm();
		}

		/// <summary>构造函数</summary>
		/// <param name="entity">实体对象</param>
		/// <param name="templateFileName">模板文件</param>
		public FrmBsdSettlementSolution(IEntity entity, String templateFileName)
			: this(entity, templateFileName, false)
		{
		}

		/// <summary>构造函数</summary>
		/// <param name="entity">实体对象</param>
		/// <param name="templateFileName">模板文件</param>
		/// <param name="readOnly">是否只读，指定编辑还是浏览实体信息</param>
		public FrmBsdSettlementSolution(IEntity entity, String templateFileName, Boolean readOnly)
			: base(entity, readOnly)
		{
			SetupFromXml(templateFileName);

			InitForm();
		}

		/// <summary>构造函数</summary>
		/// <param name="entity">实体对象</param>
		/// <param name="resourceName">模板资源文件</param>
		/// <param name="asm">模板资源文件所在程序集</param>
		public FrmBsdSettlementSolution(IEntity entity, String resourceName, Assembly asm)
			: this(entity, resourceName, asm, false)
		{
		}

		/// <summary>构造函数</summary>
		/// <param name="entity">实体对象</param>
		/// <param name="resourceName">模板资源文件</param>
		/// <param name="asm">模板资源文件所在程序集</param>
		/// <param name="readOnly">是否只读，指定编辑还是浏览实体信息</param>
		public FrmBsdSettlementSolution(IEntity entity, String resourceName, Assembly asm, Boolean readOnly)
			: base(entity, readOnly)
		{
			SetupFromXmlResource(resourceName, asm);

			InitForm();
		}

		/// <summary>构造函数</summary>
		/// <param name="entity">实体对象</param>
		/// <param name="stream">模板数据流</param>
		public FrmBsdSettlementSolution(IEntity entity, Stream stream)
			: this(entity, stream, false)
		{
		}

		/// <summary>构造函数</summary>
		/// <param name="entity">实体对象</param>
		/// <param name="stream">模板数据流</param>
		/// <param name="readOnly">是否只读，指定编辑还是浏览实体信息</param>
		public FrmBsdSettlementSolution(IEntity entity, Stream stream, Boolean readOnly)
			: base(entity, readOnly)
		{
			SetupFromXmlStream(stream);

			InitForm();
		}

		#endregion

		#endregion

		#region -- 窗体事件 --

		#region - method InitComponent -

		///// <summary>控件初始化</summary>
		protected override void InitComponent()
		{
			base.InitComponent();
      if (frmCode == null) { frmCode = FindControl("frmCode") as TextBoxX; }

			this.OnSaving += new System.EventHandler<CuteSprite.Eme.UI.Utils.EntityFormEventArgs>(this.FrmSettlementSolution_OnSaving);
			this.OnValid += new System.EventHandler<CuteSprite.Eme.UI.Utils.EntityFormEventArgs>(this.FrmBsdSettlementSolution_OnValid);
		}

		#endregion

		#region - 实体保存 -

		private void FrmSettlementSolution_OnSaving(object sender, EntityFormEventArgs e)
		{
		}

		#endregion

		#region -- 实体验证 --

		private void FrmBsdSettlementSolution_OnValid(object sender, EntityFormEventArgs e)
		{
      if (frmCode.Text == String.Empty)
      {
        MessageBoxEx.Show("代码不能为空,请输入代码！", this.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning);
        e.Cancel = true;
        return;
      }
		}

		#endregion

		#endregion
	}
}